package org.example.myl.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.myl.common.Response;
import org.example.myl.common.ResponseCode;
import org.example.myl.entity.vo.VoCourse;
import org.example.myl.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/course")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;
    //返回每门课的平均成绩
    @RequestMapping(value = "/querytAvgScore", method = RequestMethod.GET)
    public Response<List<VoCourse>>  getCourseAvgScore(){
        List<VoCourse> list =courseService.getCourseAvgScore();
        if (list!=null){
            return Response.<List<VoCourse>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(list)
                    .build();
        }else{
            return Response.<List<VoCourse>>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }



    }

}
